#!/usr/bin/env python
import pika
import sys

credentials = pika.PlainCredentials(username='chf', password='123456')  # mq用户名和密码
connection = pika.BlockingConnection(pika.ConnectionParameters(host='117.72.79.182', port=5672, credentials=credentials))
channel = connection.channel()

channel.queue_declare(queue='task_queue', durable=True)

message = ' '.join(sys.argv[1:]) or "Hello World!"
for i in range(20):
    channel.basic_publish(
        exchange='',
        routing_key='task_queue',
        body=message,
        properties=pika.BasicProperties(
            delivery_mode=pika.DeliveryMode.Persistent
        ))
print(f" [x] Sent {message}")
connection.close()